/*团队日志
彭济
9-24*/
import BasicController from './../BasicController'
import ErrorHandlerCode from './../../util/ErrorHandlerCode'
import {TeamlogModel} from '../../model'

class TeamlogController extends BasicController{
	insertLog(req,res,next){
		if(!super.isEmptyParameter(req.body.diary_title)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'diary_title 为必填参数'
            })
            return;
		}
		if(!super.isEmptyParameter(req.body.type)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'type 为必填参数'
            })
            return;
		}
		if(!super.isEmptyParameter(req.body.author)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'author 为必填参数'
            })
            return;
		}
		if(!super.isEmptyParameter(req.body.content)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'content 为必填参数'
            })
            return;
		}
		if(!super.isEmptyParameter(req.body.is_publish)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'is_publish 为必填参数'
            })
            return;
		}
		TeamlogModel.insertLog(req.body).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	delTeamlog(req,res){
        if(!super.isEmptyParameter(req.body.id)){
            res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
        }
        TeamlogModel.delLogById(req.body.id).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    listpageTeamlog(req,res){
        if(!super.isEmptyParameter(req.body.page_size)){
            req.body.page_size = 10;
        }
        if(!super.isEmptyParameter(req.body.page_no)){
            req.body.page_no = 1;
        }
        TeamlogModel.logPaging(req.body).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    updateTeamlog(req,res){
        if(!super.isEmptyParameter(req.body.id)){
            res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
        }
        TeamlogModel.logUpdateById(req.body).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
    findPublishList(req,res){
        if(!super.isEmptyParameter(req.body.is_publish)){
            res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'is_publish 为必填参数'
            });
            return;
        }
        TeamlogModel.findListPublish().then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
    }
}
module.exports = new TeamlogController();